package fr.upmc.i3s.upmcontact.contents;

import java.util.Date;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;

import fr.upmc.i3s.upmcontact.tools.DateUtils;

@JsonIgnoreProperties(ignoreUnknown = true)
public class MerchantInfo extends Published {

	private static final long serialVersionUID = 4267550288558264043L;
	
	public static final int STATE_SHORTLY_AVAILABLE = 0;
	public static final int STATE_ONGOING = 1;
	public static final int STATE_ENDED = 2;
	
	private Date beginDate;
	private Date endDate;
	private String conditions;
	private String merchantAddress;
	
	public MerchantInfo() {
		super();
		this.beginDate = null;
		this.endDate = null; 
		this.conditions = null;
		this.merchantAddress = null;
	}
	
	public MerchantInfo(String id, Date createdAt, Date updatedAt,
						String title, String description, String photoPath, String link, User publishedBy,
						Date beginDate, Date endDate, String conditions, String merchantAddress) {
		super();
		this.beginDate = beginDate;
		this.endDate = endDate;
		this.conditions = conditions;
		this.merchantAddress = merchantAddress;
	}
	
	public int getPromotionStatus() {
		if(DateUtils.isTodayBefore(beginDate)) {
			return STATE_SHORTLY_AVAILABLE;
		} else if(DateUtils.isTodayAfter(endDate)) {
			return STATE_ENDED;
		} 
		return STATE_ONGOING;
	}

	public Date getBeginDate() {
		return beginDate;
	}

	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public String getConditions() {
		return conditions;
	}

	public void setConditions(String conditions) {
		this.conditions = conditions;
	}

	public String getMerchantAddress() {
		return merchantAddress;
	}

	public void setMerchantAddress(String merchantAddress) {
		this.merchantAddress = merchantAddress;
	}
	
	@Override
	public int hashCode() {
		return super.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		MerchantInfo other = (MerchantInfo) obj;
		if (beginDate == null) {
			if (other.beginDate != null)
				return false;
		} else if (!beginDate.equals(other.beginDate))
			return false;
		if (conditions == null) {
			if (other.conditions != null)
				return false;
		} else if (!conditions.equals(other.conditions))
			return false;
		if (endDate == null) {
			if (other.endDate != null)
				return false;
		} else if (!endDate.equals(other.endDate))
			return false;
		if (merchantAddress == null) {
			if (other.merchantAddress != null)
				return false;
		} else if (!merchantAddress.equals(other.merchantAddress))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return super.toString() + " MerchantInfo [beginDate=" + beginDate + ", endDate=" + endDate
				+ ", conditions=" + conditions + ", merchantAddress="
				+ merchantAddress + "]";
	}
	
}
